// axios——设置请求
import axios from 'axios'

const http = axios.create({
  baseURL: 'http://192.168.1.40:8080',
  timeout: 8000,
  data: {},
  headers: {
    'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  }
})
    // 请求前
http.interceptors.request.use(
  config => {
  	let token = localStorage.getItem('token')
    if (token) {
      config.headers.Authorization = token
    }
    return config
  },
  error => {
    return Promise.reject(error)
  })
// 请求后
http.interceptors.response.use(
    response => {
      return response
    },
    error => {
      if (error.response) {
        switch (error.response.status) {
          case 401:
            // 401 清除token信息并跳转到登录页面
            this.$router.replace({path: '/login'})
        }
      }
      return Promise.reject(error.response.data)
    })

export default http

